

import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';


class _PageFullWidget extends StatefulWidget {
  bool? isAutomaticKeepAlive;
  Widget child;
  _PageFullWidget({super.key,this.isAutomaticKeepAlive,required this.child});

  @override
  State<_PageFullWidget> createState() => _PageFullWidgetState();
}

class _PageFullWidgetState extends State<_PageFullWidget> with AutomaticKeepAliveClientMixin{
  @override
  Widget build(BuildContext context) {
    return widget.child;
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => (widget.isAutomaticKeepAlive??false);
}


/**
 * 普通页面和 GetWidget 一起使用，需要注册路由并绑定viewmodel
 * 例子：GetPage(name: routePage, page: ()=>RoutePage(),binding: BindingsBuilder(()=>[Get.lazyPut(() => CommViewModel())])),
 */
Widget PageRouteBuild<T extends GetxController>({Key? key,required Function(T) builder}){
  return GetBuilder(
      builder: (T controller)=>builder(controller)
  );
}
/**
 * 用于TabBar+TabBarView的情况，不需要注册路由
 */
Widget PageTabBuild<T extends GetxController>({
  Key? key,bool? isAutomaticKeepAlive,
  required T initController,
  required String tag,
  required Function(T) builder
}){
  return _PageFullWidget(
    isAutomaticKeepAlive: isAutomaticKeepAlive,
    child: GetBuilder(
        init: Get.put(initController,tag: tag),
        tag: tag,
        builder: (T controller)=>builder(controller)
    ),
  );
}

/**
 * 用于new页面和 GetWidget 一起使用，不需要注册路由
 */
Widget PageNewBuild<T extends GetxController>({
    Key? key,
    bool? isAutomaticKeepAlive,
    required T initController,
    required Function(T) builder}){
  return GetBuilder(
      // init: initController,
      init: Get.put(initController),
      global: isAutomaticKeepAlive??false,
      builder: (T controller)=>builder(controller)
  );
}
